package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import com.ruoyi.system.domain.SysCanteen;
import com.ruoyi.system.service.ISysCanteenService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 食堂信息Controller
 *
 * @author jijinwu
 * @date 2024-07-22
 */
@Api(tags = "食堂信息")
@RestController
@RequestMapping("/system/canteen")
public class SysCanteenController extends BaseController
{
    @Autowired
    private ISysCanteenService sysCanteenService;

    /**
     * 查询食堂信息列表
     */
    @ApiOperation(value = "查询食堂信息列表")
    @PreAuthorize("@ss.hasPermi('system:canteen:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysCanteen sysCanteen)
    {
        startPage();
        List<SysCanteen> list = sysCanteenService.selectSysCanteenList(sysCanteen);
        return getDataTable(list);
    }

    /**
     * 导出食堂信息列表
     */
    @ApiOperation(value = "导出食堂信息列表")
    @PreAuthorize("@ss.hasPermi('system:canteen:export')")
    @Log(title = "食堂信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysCanteen sysCanteen)
    {
        List<SysCanteen> list = sysCanteenService.selectSysCanteenList(sysCanteen);
        ExcelUtil<SysCanteen> util = new ExcelUtil<SysCanteen>(SysCanteen.class);
        util.exportExcel(response, list, "食堂信息数据");
    }

    /**
     * 获取食堂信息详细信息
     */
    @ApiOperation(value = "获取食堂信息详细信息")
    @PreAuthorize("@ss.hasPermi('system:canteen:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysCanteenService.selectSysCanteenById(id));
    }

    /**
     * 新增食堂信息
     */
    @ApiOperation(value = "新增食堂信息")
    @PreAuthorize("@ss.hasPermi('system:canteen:add')")
    @Log(title = "食堂信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody SysCanteen sysCanteen)
    {
        return toAjax(sysCanteenService.insertSysCanteen(sysCanteen));
    }

    /**
     * 修改食堂信息
     */
    @ApiOperation(value = "修改食堂信息")
    @PreAuthorize("@ss.hasPermi('system:canteen:edit')")
    @Log(title = "食堂信息", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody SysCanteen sysCanteen)
    {
        return toAjax(sysCanteenService.updateSysCanteen(sysCanteen));
    }

    /**
     * 删除食堂信息
     */
    @ApiOperation(value = "删除食堂信息")
    @ApiImplicitParam(name = "id", value = "食堂信息D",paramType = "query", dataType = "Long")
    @PreAuthorize("@ss.hasPermi('system:canteen:remove')")
    @Log(title = "食堂信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysCanteenService.deleteSysCanteenByIds(ids));
    }
}
